package com.bl.weilan.manager.controller.companystockholder;

import com.bl.weilan.common.ApiResponseBody;
import com.bl.weilan.dao.model.CompanyStockholderEntity;
import com.bl.weilan.manager.controller.BaseController;
import com.bl.weilan.service.biz.companystockholder.CompanyStockholderService;
import com.bl.weilan.service.vo.DelBody;
import com.bl.weilan.service.vo.DelListBody;
import com.bl.weilan.service.vo.companystockholder.CompanyStockholderAddVo;
import com.bl.weilan.service.vo.companystockholder.CompanyStockholderListVo;
import com.bl.weilan.service.vo.companystockholder.CompanyStockholderModVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;


@RestController
@Log4j2
@RequestMapping(value = {"/weilan/manager/stockholder"})
@Api(value = "股东信息", description = "股东信息")

public class CompanyStockholderController extends BaseController {
    @Autowired
    CompanyStockholderService companystockholderService;

    @ApiOperation(value = "根据公司id获取公司的股东列表信息", notes = "根据公司id获取公司的股东信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "companyId", value = "公司id", required = true, paramType = "query", dataType = "String", defaultValue = ""),
            @ApiImplicitParam(name = "page", value = "页数", required = false, paramType = "query", dataType = "int", defaultValue = "1"),
            @ApiImplicitParam(name = "size", value = "每页大小", required = false, paramType = "query", dataType = "int", defaultValue = "10")})
    @GetMapping(value = {"/get_list"})
    public ApiResponseBody<CompanyStockholderListVo> companystockholderList(
            @RequestParam(value = "companyId", required = true, defaultValue = "") String companyId,
            @RequestParam(value = "page", required = false, defaultValue = "1") int page,
            @RequestParam(value = "size", required = false, defaultValue = "10") int size,
            HttpServletRequest request) {

        Pageable pageable = new PageRequest(page - 1, size);

        CompanyStockholderListVo companystockholderListVo = companystockholderService.getCompanyStockholderLists(companyId,pageable);

        return ApiResponseBody.createSuccessBody(companystockholderListVo);
    }

    @ApiOperation(value = "获取股东详情信息", notes = "获取股东详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "String")})
    @GetMapping(value = {"/get_detail"})
    public ApiResponseBody<CompanyStockholderListVo> companystockholderList(
            @RequestParam(value = "id", required = true) String id,
            HttpServletRequest request) {

        CompanyStockholderEntity companystockholderEntity = companystockholderService.getCompanyStockholderById(id);

        return ApiResponseBody.createSuccessBody(companystockholderEntity);
    }

    @ApiOperation(value = "增加股东信息", notes = "增加股东信息 ")
    @ApiImplicitParams({})
    @PostMapping(value = {"/add"})
    public ApiResponseBody add(
            @Valid @RequestBody CompanyStockholderAddVo body, BindingResult result,
            HttpServletRequest request) {

        ApiResponseBody validResult = validParams(result);
        if (validResult != null) {
            return validResult;
        }

        companystockholderService.addCompanyStockholder(body);

        return ApiResponseBody.createSuccessBody(null);
    }

    @ApiOperation(value = "删除批量", notes = "删除批量 ")
    @ApiImplicitParams({
    })
    @PostMapping(value = {"/del_list"})
    public ApiResponseBody delList(
            @Valid @RequestBody DelListBody body, BindingResult result,
            HttpServletRequest request) {

        companystockholderService.delList(body);

        return ApiResponseBody.createSuccessBody(null);
    }

    @ApiOperation(value = "删除增加股东信息", notes = "删除增加股东信息 ")
    @ApiImplicitParams({
    })
    @PostMapping(value = {"/del"})
    public ApiResponseBody del(
            @Valid @RequestBody DelBody body, BindingResult result,
            HttpServletRequest request) {


        companystockholderService.del(body);

        return ApiResponseBody.createSuccessBody(null);
    }

    @ApiOperation(value = "修改增加股东信息", notes = "修改增加股东信息")
    @ApiImplicitParams({})
    @PostMapping(value = {"/modify"})
    public ApiResponseBody modify(
            @Valid @RequestBody CompanyStockholderModVo body, BindingResult result,
            HttpServletRequest request) {

        ApiResponseBody validResult = validParams(result);
        if (validResult != null) {
            return validResult;
        }

        companystockholderService.modify(body);

        return ApiResponseBody.createSuccessBody(null);
    }

}
